package demo1;

class Money implements Cloneable{
    public double m = 19.9;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Person implements Cloneable{
    public String name;
    public int age;
    public Money money = new Money();

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person tmp = (Person) super.clone();
        this.money = (Money)this.money.clone();
        return tmp;
        //return super.clone();
    }
}
public class Test {

    public static void main(String[] args) throws CloneNotSupportedException {
        Person person = new Person("张三",18);
        Person person1 = (Person)person.clone();
        System.out.println(person.money.m);
        System.out.println(person1.money.m);
        person.money.m = 99.99;
        System.out.println(person.money.m);
        System.out.println(person1.money.m);
    }
}
